package his.controller;

import his.entity.Register;
import his.service.QueryCaseHistoryService;
import his.vo.PrescriptionsFilled;
import his.vo.RegisterVO;
import his.vo.ReturnDrugsVO;
import his.vo.ReturnRegistVO;
import org.example.his.common.api.CommonResponse;
import org.example.his.common.auth.JwtAuth;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

@RestController
@RequestMapping("/patient")
public class QueryCaseHistoryController {

    @Autowired
    private QueryCaseHistoryService queryCaseHistoryService;

    /**
     * 测试JWT
     */
    @GetMapping("/JWTT")
    public String JWTT(
           @RequestParam("a") String a
    ){
        return JwtAuth.jwtEncipher(a,a);
    }

    /**
     * 解密
     */
    @GetMapping("/JWTTT")
    public String JWTTT(
            @RequestParam("a") String a
    ){
        return JwtAuth.jwtDecrypt(a);
    }

    /**
     * API1 查询历史病历
     * @param token
     * @return
     */
    @GetMapping("/queryCaseHistory")
    public CommonResponse<List<RegisterVO>> queryCaseHistory(
            @RequestParam("token") String token
    ){
        return queryCaseHistoryService.queryCaseHistory(token);
    }

    /**
     * API2 查看已开处方
     */
     @GetMapping("/viewPrescriptionsFilled")
     public CommonResponse<List<PrescriptionsFilled>> viewPrescriptionsFilled(
             @RequestParam("token") String token
     ){
         return queryCaseHistoryService.viewPrescriptionsFilled(token);
     }

    /**
     * API3 退号
     */
    @GetMapping("/returnNumber")
    public CommonResponse<String> del_regist(
            @RequestParam("CaseNumber") String CaseNumber ,
            @RequestParam("VisitState") int VisitState){
        return queryCaseHistoryService.del_regist(CaseNumber , VisitState);
    }

    /**
     * API4 退费
     */
    @GetMapping("/refunds")
    CommonResponse<String> refunds(
            @RequestParam("RegistID") int RegistID ,
            @RequestParam("CaseNumber") String CaseNumber ,
            @RequestParam("ItemID") int ItemID ,
            @RequestParam("price") BigDecimal price ,
            @RequestParam("ItemType") int ItemType ,
            @RequestParam("Status") String Status ,
            @RequestParam("totalPrice") BigDecimal totalPrice){
        return queryCaseHistoryService.refunds(RegistID,CaseNumber,ItemID,price,ItemType,Status,totalPrice);
    }

    /**
     * API5 退药
     */
    @DeleteMapping("/returnMedical")
    public CommonResponse<String> returnMedical(
            @RequestParam("PrescriptionID") String PrescriptionID
    ){
        return queryCaseHistoryService.returnMedical(PrescriptionID);
    }

    /**
     * API6 退项目
     */
    @DeleteMapping("/returnProject")
    public CommonResponse<String> del_no_init_pro(
            @RequestParam("MedicalID") int MedicalID,
            @RequestParam("RegistID") int RegistID,
            @RequestParam("ItemID") int ItemID
    ){
        return queryCaseHistoryService.del_no_init_pro(
                MedicalID,
                RegistID,
                ItemID
        );
    }

    /**
     * API7 获取挂号消费记录 用于退号的项目
     */
    @GetMapping("/getPatientCostsRegist")
    public CommonResponse<List<ReturnRegistVO>> getPatientCostsRegist(
            @RequestParam("token") String token
    ){
        return queryCaseHistoryService.getPatientCostsRegist(token);
    }

    /**
     * API8 获取药品的消费记录 用于退号的项目
     */
    @GetMapping ("/getPatientCostsDrugs")
    public CommonResponse<List<PrescriptionsFilled>> getPatientCostsDrugs(
            @RequestParam("token") String token
    ){
        return queryCaseHistoryService.getPatientCostsDrugs(token);
    }
}
